package ipad.asia.dao;

import ipad.asia.entity.SeckillProduct;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Lock;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.LockModeType;
import java.util.List;

@Repository
public interface SecKillProductDao extends JpaRepository<SeckillProduct,Long> {
    //悲观锁
    @Transactional
    @Lock(LockModeType.PESSIMISTIC_WRITE)
    SeckillProduct findByProductId(int productId);
    List<SeckillProduct> findAll();
//    乐观锁
    @Query("update SeckillProduct set number=?1 where productId=?2")
    @Modifying
    @Transactional
    void update(int number,int productId);
    void deleteByProductId(Integer id);

}
